package exemplos.ex02.view;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

/**
 * Servlet implementation class UsuarioLogado
 */
@WebServlet("/loginRealizado")
public class UsuarioLogado extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public UsuarioLogado() {
        super();
    }

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		PrintWriter out = response.getWriter();
		response.setContentType("text/html;charset=utf-8");
		
		HttpSession session = request.getSession();
		String login = (String) session.getAttribute("login");
		if (login!=null && !login.equals("")) {	
			out.println("<html>\n"+
						"<head>\n"+
						"<meta charset=\"utf-8\">\n"+
						"<title>Página principal</title>\n"+
						"</head>\n"+
						"<body>\n"+
						"<h1>Usuário Logado com Sucesso</h1>\n"+
						"<p>Seja bem vindo <b>"+login+"</b>!</p>\n"+
						"</body>\n"+
						"</html>");
			out.close();
			return;
		}
		
		response.sendRedirect("exemplo02/index.html");
	}

}
